#include<iostream>
using namespace std;
int arr[6][6];
int main()
{
	int idx1 = 0, idx2 = 0;
	for (int i = 1; i <= 5; i++) {
		for (int j = 1; j <= 5; j++) {
			cin >> arr[i][j];
			if (arr[i][j] == 1) {
				idx1 = i;
				idx2 = j;
			}
		}
	}
	cout << abs(idx1 - 3) + abs(idx2 - 3) << endl;
	return 0;
}